package com.uchedao.vehicledetection.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.uchedao.vehicledetection.R;
import com.uchedao.vehicledetection.model.ResultInt;
import com.uchedao.vehicledetection.view.widget.stickylistheaders.StickyListHeadersAdapter;

public class EngineObdAdapter extends BaseAdapter implements
		StickyListHeadersAdapter {
	private Context mContext;
	private ResultInt[] results;
	private LayoutInflater inflater;

	// private String[] values;

	public EngineObdAdapter(Context context, ResultInt[] result) {
		inflater = LayoutInflater.from(context);
		mContext = context;
		// values = GlobalInfo.resources
		// .getStringArray(R.array.skeleton_value_entries);
		results = result;
	}

	@Override
	public int getCount() {
		return results.length;
	}

	@Override
	public Object getItem(int position) {
		return results[position];
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	class ViewHolder {
		TextView titleTv;
		TextView valueTv;
		TextView resultTv;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = inflater.inflate(R.layout.item_condition_engine_obd,
					null);
			convertView.setTag(viewHolder);
			viewHolder.titleTv = (TextView) convertView
					.findViewById(R.id.engine_obd_item_tv);
			viewHolder.valueTv = (TextView) convertView
					.findViewById(R.id.engine_obd_item_tv_value_tv);
			viewHolder.resultTv = (TextView) convertView
					.findViewById(R.id.engine_obd_item_result_tv);

		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		ResultInt result = results[position];

		viewHolder.titleTv.setText(result.name);
		if (result.result == -1) {
			viewHolder.valueTv.setText(R.string.condition_paint_tag);
			viewHolder.resultTv.setText(R.string.condition_paint_tag);
		} else {
			viewHolder.valueTv.setText(result.result);
		}
		return convertView;
	}

	public View getHeaderView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = inflater.inflate(
					R.layout.item_condition_engine_obd_subject, null);
		}

		return convertView;
	}

	@Override
	public long getHeaderId(int position) {
		return 0;
	}

}
